import { computed, ref } from 'vue'

// 类型 start入学 end毕业
type EduDatePickerType = 'start' | 'end'

export function useEduDatePicker() {
	const selected = ref(Date.now())
	const pickerType = ref<EduDatePickerType>('start')
	const show = ref(false)

	const open = (type: EduDatePickerType, value: string) => {
		if (value) {
			selected.value = new Date(value).getTime()
		} else {
			selected.value = Date.now()
		}

		pickerType.value = type
		show.value = true
	}

	const close = () => {
		show.value = false
	}

	return {
		selected,
		pickerType,
		isStartPicker: computed(() => pickerType.value === 'start'),
		isEndPicker: computed(() => pickerType.value === 'end'),
		show,
		open,
		close,
	}
}
